package com.ruoyi.coupon.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.coupon.domain.TbCoupon;
import com.ruoyi.coupon.service.ITbCouponService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 优惠卷列Controller
 * 
 * @author ruoyi
 * @date 2023-02-02
 */
@RestController
@RequestMapping("/coupon")
public class TbCouponController extends BaseController
{
    @Autowired
    private ITbCouponService tbCouponService;

    /**
     * 查询优惠卷列列表
     */
    @RequiresPermissions("coupon:coupon:list")
    @GetMapping("/list")
    public TableDataInfo list(TbCoupon tbCoupon)
    {
        startPage();
        List<TbCoupon> list = tbCouponService.selectTbCouponList(tbCoupon);
        return getDataTable(list);
    }

    /**
     * 导出优惠卷列列表
     */
    @RequiresPermissions("coupon:coupon:export")
    @Log(title = "优惠卷列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCoupon tbCoupon)
    {
        List<TbCoupon> list = tbCouponService.selectTbCouponList(tbCoupon);
        ExcelUtil<TbCoupon> util = new ExcelUtil<TbCoupon>(TbCoupon.class);
        util.exportExcel(response, list, "优惠卷列数据");
    }

    /**
     * 获取优惠卷列详细信息
     */
    @RequiresPermissions("coupon:coupon:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbCouponService.selectTbCouponById(id));
    }

    /**
     * 新增优惠卷列
     */
    @RequiresPermissions("coupon:coupon:add")
    @Log(title = "优惠卷列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCoupon tbCoupon)
    {
        return toAjax(tbCouponService.insertTbCoupon(tbCoupon));
    }

    /**
     * 修改优惠卷列
     */
    @RequiresPermissions("coupon:coupon:edit")
    @Log(title = "优惠卷列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCoupon tbCoupon)
    {
        return toAjax(tbCouponService.updateTbCoupon(tbCoupon));
    }

    /**
     * 删除优惠卷列
     */
    @RequiresPermissions("coupon:coupon:remove")
    @Log(title = "优惠卷列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCouponService.deleteTbCouponByIds(ids));
    }

    /**
     * 优惠卷id查询
     */
    @GetMapping("findcouponById")
    public TbCoupon findcouponById(@RequestParam("id") Long id)
    {
        return tbCouponService.selectTbCouponById(id);
    }
}
